<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
html,body {
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	height: 100%;
}
</style>
<script src="../scripts/boot.js" type="text/javascript"></script>
</head>

<body>
<div class="mini-splitter" style="width:100%;height:100%;">
	<div size="240" showCollapseButton="true">
		<div class="mini-fit">
			<ul id="tree1" class="mini-tree" url="../../admin/data/deptTree.txt" style="width:100%;"
				showTreeIcon="true" textField="name" idField="id" parentField="pid" resultAsTree="false">
			</ul>
		</div>
	</div>
	<div showCollapseButton="true">
		<div class="mini-toolbar">
			<a class="mini-button" plain="true" onclick="edit" iconcls="icon-edit">编辑</a>
			<a class="mini-button" plain="true" onclick="search" iconcls="icon-find">筛选</a>
			<a class="mini-button" plain="true" onclick="previewDia" iconcls="icon-node">流程图</a>
		</div>
		<div class="mini-fit"><!-- onrowdblclick="edit" 双击事件 -->
			<div id="datagrid1" class="mini-datagrid" allowResize="false" pageSize="20" url="listData"
				style="width:100%;height:100%;" borderStyle="border-top:none;" idField="id" multiSelect="true"
			>
				<div property="columns">
					<div field="name" width="100" headerAlign="left" align="left" allowSort="false">节点名称</div>
					<div field="days" width="300" headerAlign="left" align="left" allowSort="false">处理天数</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
var basepath = window.location.pathname + "/../";

//初始化
mini.parse();
var grid = mini.get("datagrid1");
grid.load();
//树
var tree = mini.get("tree1");
var preview;

tree.on("nodeselect", function (e) {
	preview="preview?type="+e.node.id;

	if (e.isLeaf) {
		grid.load({ caseType: e.node.id });
	} else {
		grid.setData([]);
		grid.setTotalCount(0);
	}
});

//新增//状态
function exchangeStatus(e){
	var status = e.row.status;
	if(status == '1'){
		return "<span style='color:#18a689;'>正常</span>";
	}else if(status == '2'){
		return "<span style='color:#ff0000;'>逾期</span>";
	}else{
		return "";
	}
}
function previewDia() {
	var win = mini.open({
		url: basepath + preview,
		title: "流程图",
		width: 800,
		height: 600,
		allowResize: false,
		onload: function () {

		},
		ondestroy: function (action) {

		}
	});
	win.max();
}
//编辑
function edit() {
	var row = grid.getSelected();
	if(row == null){
		mini.alert("请选择一条记录");
		return;
	}
	mini.open({
		url : basepath+"edit",
		title : "编辑",
		width : 400,
		height : 280,
		allowResize: false,
		onload : function() {
			var iframe = this.getIFrameEl();
			iframe.contentWindow.SetData(row);
		},
		ondestroy : function(action) {
			if (action == "save") {
				grid.reload();
			}
		}
	});
}
//删除
function remove() {
	var rows = grid.getSelecteds();
	if(rows == null || rows.length<=0){
		mini.alert("请选择一条记录");
		return;
	}
	mini.showMessageBox({
		title: "提示",
		width: 250,
		buttons: ["ok", "cancel"],
		message: "确认删除选中的记录吗？",
		iconCls: "mini-messagebox-question",
		callback: function (action) {
			if (action == "ok") {
				executeRemove(rows);
			}
		}
	});
}
//执行删除
function executeRemove(rows){
	var ids = [];
	for ( var i = 0, l = rows.length; i < l; i++) {
		var r = rows[i];
		ids.push(r.id);
	}
	var id = ids.join(',');
	mini.mask({
		el: document.body,
		cls: 'mini-mask-loading',
		html: '正在处理，请耐心等待 ...'
	}); 

	$.ajax({
		url : "delete",
		type : "post",
		data : {
			ids : id
		},
		success : function(text) {
			mini.unmask();
			var result = mini.decode(text);
			if (result.res) {
				grid.reload();
			} else {
				mini.showMessageBox({
					title : "提示",
					width : 250,
					buttons : ["ok"],
					iconCls : "mini-messagebox-warning",
					message : result.msg
				});
			}
		},
		error : function(jqXHR, textStatus, errorThrown) {
			mini.unmask();
			alert(jqXHR.responseText);
		}
	});
}
//筛选
function search(){
	mini.open({
		url : basepath+"search",
		title : "筛选",
		width : 800,
		height : 500,
		allowResize : false,
		ondestroy : function (action) {
			if(action == "search"){
				var iframe = this.getIFrameEl();
				var data = iframe.contentWindow.GetData();
				console.log(data);
				data = mini.clone(data);
				grid.load(data);
			}
		}
	});
}
//导入Excel
function importExcel() {
	mini.open({
		url : basepath+"import",
		title : "导入报名清单数据",
		width : 400,
		height : 200,
		allowResize : false,
		ondestroy : function (action) {
			if(action='ok'){
				grid.reload();
			}
		}
	});
}
//导出Excel
function exportExcel(){
	mini.confirm("确定导出记录？", "导出",
		function (action) {
			if (action == "ok") {
				executeExport();
			} else {
			}
		}
	);
}
//执行导出
function executeExport(){
	var data = grid.getLoadParams();
	mini.mask({
		el: document.body,
		cls: 'mini-mask-loading',
		html: '正在导出...'
	});
	$.ajax({
		url : "export",
		type : "post",
		data : data,
		dataType : "json",
		success : function(resultBean) {
			mini.unmask();
			if(resultBean.res){
				window.location.href = resultBean.data;
			}else{
				mini.alert(resultBean.msg);
			}
		},
		error : function(redata) {
			mini.unmask();
		}
	});
}
</script>
</body>
</html>
